from selenium import webdriver
import time
import os
import unittest
from public.url import wkurl
from public.wklogin import wklogin
from selenium.webdriver.common.keys import Keys


class Test_XLR(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Chrome()
        url=wkurl(self.driver).test_url()
        self.driver.get(url+"/index.html#/login?redirect=%2F404")
        self.driver.maximize_window()
        time.sleep(3)
        print("start_time"+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time())))

    def tearDown(self):
        file_dir="D:/test/screenshot/"
        if not os.path.exists(file_dir):
            os.makedirs(os.path.join("D:/","test","screenshot"))
        print("end_time"+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time())))
        screen_name=file_dir+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))+".png"
        self.driver.get_screenshot_as_file(screen_name)
        self.driver.quit()

    def testGonghai_01(self):
        '''点击公海能否成功进入公海页面'''
        wklogin(self.driver).login() #调入登录方法
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(8)
        self.driver.find_element_by_xpath("//span[text()='公海']").click()
        time.sleep(6)
        a=self.driver.find_element_by_xpath("//div[text()='公海管理']").text

        self.assertEqual("公海管理",a)


    def testGonghai_02(self):
        '''能否成功从公海领取客户'''
        wklogin(self.driver).login() #调入登录方法
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(8)
        self.driver.find_element_by_xpath("//span[text()='公海']").click()
        time.sleep(6)
        a=self.driver.find_element_by_xpath("//div/div[4]/div[2]/table[1]/tbody[1]/tr[3]/td[2]/div[1]").text
        self.driver.find_element_by_xpath("//div[4]/div[2]/table/tbody/tr[3]/td[1]/div/label/span/span").click()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[text()='领取']").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//div/div/div[3]/button[2]/span").click()
        time.sleep(3)
        b=self.driver.find_element_by_xpath("//div/div[4]/div[2]/table[1]/tbody[1]/tr[3]/td[2]/div[1]").text
        #进入客户
        self.driver.find_element_by_xpath('//div[@class="container"]/ul/a[4]/li/span').click()
        time.sleep(6)
        c=self.driver.find_element_by_xpath('//div[@class="el-table__fixed"]/div[2]/table/tbody/tr[1]/td[3]/div').text

        self.assertNotEqual(a,b)
        self.assertEqual(a,c)


    def testXjchanpin_03(self):
        '''能否成功新建产品'''
        wklogin(self.driver).login() #调入登录方法
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(8)
        self.driver.find_element_by_xpath("//li/span[text()='产品']").click()
        time.sleep(6)
        self.driver.find_element_by_xpath("//span[text()='新建产品']").click()
        time.sleep(2)
        bm= time.strftime("%Y%m%d", time.localtime(time.time()))
        self.driver.find_element_by_xpath('//form/div[3]/div/div/input').send_keys(bm)
        self.driver.find_element_by_xpath("//form/div[2]/div/span/span").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//div/ul/li[1]/span[text()='默认']").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//form/div[4]/div/div/input").send_keys(200)
        self.driver.find_element_by_xpath("//form/div[6]/div/div/div[1]/input").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//span[text()='上架']").click()
        self.driver.find_element_by_xpath("//div[@class='handle-bar']/button[2]/span[text()='保存']").click()
        time.sleep(3)
        b=self.driver.find_element_by_xpath("//div/div[3]/table/tbody/tr[1]/td[4]/div").text

        self.assertEqual(bm,b)

    def testSyzn_04(self):
        '''点击商业智能否成功进入'''
        wklogin(self.driver).login()  # 调入登录方法
        self.driver.find_element_by_xpath("//div[text()='商业智能']").click()
        time.sleep(5)
        a=self.driver.find_element_by_xpath("//section/aside/div/ul/a[1]/li/span").text

        self.assertEqual("业绩目标完成情况",a)

    def testXmgl_05(self):
        '''点击项目管理能否成功进入'''
        wklogin(self.driver).login()  # 调入登录方法
        self.driver.find_element_by_xpath("//div[text()='项目管理']").click()
        time.sleep(5)
        a = self.driver.find_element_by_xpath("//section/aside/div/ul/a[1]/li/span").text

        self.assertEqual("统计分析", a)



    def testTxunlu_06(self):
        '''能否通过输入员工名字搜索'''
        wklogin(self.driver).login()  # 调入登录方法
        self.driver.find_element_by_xpath("//span[text()='通讯录']").click()
        time.sleep(5)
        self.driver.find_element_by_xpath('//div/div[2]/div[1]/div/input').send_keys("玄兔")
        #按回车键
        self.driver.find_element_by_xpath('//div/div[2]/div[1]/div/input').send_keys(Keys.ENTER)
        time.sleep(3)
        a=self.driver.find_element_by_xpath('//div[@id="pane-1"]/div[2]/div[2]/div[2]/div/div[1]').text

        self.assertEqual("玄兔",a)


if __name__ == "__main__":
    unittest.main()














